package com.bartender.consumer.config;

import com.bartender.consumer.filter.TokenFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenFilter tokenFilter;

    @Bean
    public FilterRegistrationBean<TokenFilter> tokenFilterRegistration() {
        FilterRegistrationBean<TokenFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(tokenFilter);
        registrationBean.addUrlPatterns("/consumer/wx_user/updateBySelf"); // 只对特定的 URL 模式应用过滤器
        registrationBean.addUrlPatterns("/common/mini/upload");
//        registrationBean.addUrlPatterns("/consumer/wx_user/list_front");
        registrationBean.addUrlPatterns("/order/order/create");
        registrationBean.addUrlPatterns("/order/order/paymentStatus");
        registrationBean.addUrlPatterns("/order/order/allSelfOrders");
        registrationBean.addUrlPatterns("/order/order/create_diy");
        registrationBean.addUrlPatterns("/order/order/evaluate");
        registrationBean.setOrder(1); // 设置过滤器的顺序，数字越小优先级越高
        return registrationBean;
    }
} 